package com.eipv.multidatasource.entity;

import com.eipv.component.mybatis.base.entity.BaseEntity;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Objects;

@Getter
@Setter
public class Table extends BaseEntity<String, String> {
    private String tableName;

    private List<Column> columns;

    private long count;

    private String foreignTableName;

    private long handled;

    private long rowsOfRead;

    private long rowsOfWrite;

    private long transferred;

    private long transferTime;

    /**
     * 正在处理的文件名
     */
    private String fileName;

    /**
     * 迁移发生的异常
     */
    private String exception;

    public boolean isFinished() {
        return count == handled;
    }

    public void updateHandled(Long update) {
        this.handled += update;
    }

    public void updateReadRows(Long update) {
        this.rowsOfRead += update;
    }

    public void updateWriteRows(Long update) {
        this.rowsOfWrite += update;
    }

    public void updateTransferred(Long update) {
        this.transferred += update;
    }

    public void updateTransferTime(Long update) {
        this.transferTime += update;
    }

    @Override
    public boolean equals(Object o) {
        Table table = (Table) o;
        return tableName.equals(table.tableName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), tableName);
    }
}
